Yes, although this method is sometimes awkward.
One of the types of loops is a "sentinel" controlled loop, where a special input value indicates that there is no more data. This idea can be used with input files as well. Say that your program is to add up the integers in a file of data. The integers are all expected to be positive integers, so the sentinel value can be any negative integer. Here is a data file where each group of student grades is followed by -1, the sentinel.
87 98 95 -1 78 82 91 84 -1
The program should average three integers in this file and four integers in the second (and not include the negative values in eithere average).